/*
 * Copyright (c) 2006, 2023, webrx.cn All rights reserved.
 *
 */

package cn.webrx;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;

/**
 * <p>Project: jse2303 - LinkedList3
 * <p>Powered by webrx On 2023-07-19 14:25:05
 * <p>描述：<p>
 *
 * @author webrx [webrx@126.com]
 * @version 1.0
 * @since 17
 */
public class LinkedList3 {
    public static void main(String[] args) {

        long ss = System.currentTimeMillis();
        long ee = System.currentTimeMillis();

        //LinkedList
        List<String> li1 = new LinkedList<>();
        ss = System.currentTimeMillis();
        for (int i = 0; i < 100000; i++) {
            li1.add("List" + i);
        }
        ee = System.currentTimeMillis();
        System.out.printf("LinkedList 0 add : %dms%n", ee - ss);

        ss = System.currentTimeMillis();
        for (int i = 0; i < 100000; i++) {
            String t = li1.get(i);
        }
        ee = System.currentTimeMillis();
        System.out.printf("LinkedList 0 read1 : %dms%n", ee - ss);


        ss = System.currentTimeMillis();
        List<String> li2 = new ArrayList<>(li1);
        for (int i = 0; i < 100000; i++) {
            String t = li2.get(i);
        }
        ee = System.currentTimeMillis();
        System.out.printf("ArrayList 0 read2 : %dms%n", ee - ss);


        ss = System.currentTimeMillis();

        //通过集合工具类对象，转成迭代器对象 .hasNext() 判断 .next();
        Iterator<String> iterator = li1.iterator();
        while (iterator.hasNext()) {
            String t = iterator.next();
        }
        ee = System.currentTimeMillis();
        System.out.printf("LinkedList 0 Iterator read3 : %dms%n", ee - ss);

    }
}
